# 使用到了jq 库， 请提前安装 yum install jq


#adb shell dumpsys window policy |grep "mScreenOnEarly=true" # 屏幕点亮
#echo  $?
#adb shell dumpsys window policy |grep "isStatusBarKeyguard=false" # 屏幕锁定
#echo $?
homepath="/Users/shangshang/Documents/android-tools/platform-tools/"
#curl -s http://www.easybots.cn/api/holiday.php\?d\=20200115 |grep ":\"0"

echo 当前时间`date "+%Y-%m-%d %H:%M:%S"`
echo "判断当前日期是否是工作日或假期"
date_cur=`date "+%Y%m%d"`
#date_cur=20220405
# 判断当前是否工作日
#curl -s http://www.easybots.cn/api/holiday.php\?d\=$date_cur |grep ":\"0"
#cur_stat=`curl -s  https://tool.bitefu.net/jiari/\?d\=$date_cur\&info\=1\&back\=json |jq ".type"`
cur_stat=`curl -s  https://tool.bitefu.net/jiari/\?d\=$date_cur\&info\=1\&back\=json |grep "\"type\":0"|wc -l`
echo $cur_stat
if [ $cur_stat -eq 0 ];then
	echo "当前是节假日。无需打卡"
	exit
else
	echo "当前是工作日，继续打卡"
fi
#exit

echo 生成随机数
num=$((RANDOM%25*60))
#num=$((RANDOM%1*60))
#num=$((RANDOM%10*60))
echo $num
sleep $num
source ~/.bashrc

echo 开始自动打卡`date "+%Y-%m-%d %H:%M:%S"`
echo 获取设备列表
$homepath/adb devices
if [ $? -eq 1 ]
then
	$homepath/adb reconnect
fi

$homepath/adb shell dumpsys window policy |grep "mScreenOnEarly=true"
if [ $? -eq 1 ]
then
	echo 屏幕未点亮，唤醒屏幕
	echo  唤醒屏幕
	$homepath/adb shell input keyevent 26
else
	echo 屏幕已点亮
	
fi 

$homepath/adb shell dumpsys window policy |grep "isStatusBarKeyguard=false"
if [ $? -eq 1 ]
then	
	echo 屏幕锁定，需要解锁
	$homepath/adb shell input keyevent 82
else
	echo 屏幕已解锁

fi

echo 打开gps
$homepath/adb shell settings put secure location_providers_allowed +gps
echo 打开wifi
$homepath/adb shell svc wifi enable

echo  先杀进程
$homepath/adb shell  am force-stop com.alibaba.android.rimet

echo 等待6秒
sleep 6

echo 打开钉钉
$homepath/adb shell am start -n com.alibaba.android.rimet/com.alibaba.android.rimet.biz.LaunchHomeActivity

echo 等待20秒
sleep 20
echo 点击工作台
$homepath/adb shell input tap 360 1300
echo 等待15秒
sleep 15
echo 点击考勤打卡
#$homepath/adb shell input tap 100 880
$homepath/adb shell input tap 100 750
echo 等待15秒
sleep 15
echo 点击打卡
$homepath/adb shell input tap 380  780
echo 等待10秒
sleep 10
echo 杀掉进程
$homepath/adb shell  am force-stop com.alibaba.android.rimet

echo 关闭屏幕
$homepath/adb shell input keyevent 26
echo 打卡完成
echo 当前时间:`date "+%Y-%m-%d %H:%M:%S"`
echo "\n\n"

